extends /templates/base-flat

block page_nav
  include ./teacher-dashboard-nav.jade

block content
  if me.isAnonymous() || (!me.isTeacher() && !view.classrooms.size())
    .container
      .access-restricted.container.text-center.m-y-3
        h5(data-i18n='teacher.access_restricted')
        p(data-i18n='teacher.teacher_account_required')
        if me.isAnonymous()
          .login-button.btn.btn-lg.btn-primary(data-i18n='login.log_in')
          a.btn.btn-lg.btn-primary-alt(href="/teachers/signup" data-i18n='teacher.create_teacher_account')
        else
          a.btn.btn-lg.btn-primary(href="/teachers/update-account" data-i18n="teachers_quote.convert_account_title")
          button#logout-button.btn.btn-lg.btn-primary-alt(data-i18n="login.log_out")

      .container
        .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3
          h5(data-i18n='teacher.what_is_a_teacher_account')
          p(data-i18n='teacher.teacher_account_explanation')

  else
    if !me.isTeacher() && !me.isAdmin()
      .alert.alert-danger.text-center
        .container
          // DNT: Temporary
          h3 ATTENTION: Please upgrade your account to a Teacher Account.
          p
            | We are transitioning to a new improved classroom management system for instructors.
            | Please convert your account to ensure you retain access to your classrooms.
          a.btn.btn-primary.btn-lg(href="/teachers/update-account") Upgrade to teacher account

    if view.state.get('shouldUpsell')
      .bg-forest
        .container
          .row
            .col-xs-9.m-t-1
              b
                span.text-uppercase(data-i18n="special_offer.special_offer")
                =': '
                span(data-i18n="special_offer.student_starter_license")
              .small-details
                i(data-i18n="special_offer.purchase_starter_licenses_to_grant", data-i18n-options=JSON.stringify(view.i18nData()))
            .col-xs-3
              a.btn.btn-lg.btn-forest-alt.m-t-2.m-b-2(href="/teachers/starter-licenses")
                b(data-i18n="general.learn_more")

    .container.m-t-5
      h3(data-i18n='teacher.enrollments')
      h4#enrollments-blurb(data-i18n="teacher.enrollments_blurb")  
      - var available = view.state.get('prepaidGroups').available
      - var pending = view.state.get('prepaidGroups').pending
      - var empty = view.state.get('prepaidGroups').empty
      - var anyPrepaids = available || pending ||  empty
      
      .text-center.m-t-3
        span.glyphicon.glyphicon-question-sign
        =' '
        a#how-to-enroll-link(data-i18n="teacher.how_to_apply_licenses")

      .row.m-t-3
        if anyPrepaids
          #prepaids-col.col-md-9
            if _.size(available) > 0
              h5.m-b-1(data-i18n="teacher.available_credits")
              .row
                for prepaid in available
                  .prepaid-card-container.col-sm-4.col-xs-6
                    +prepaidCard(prepaid)

            if _.size(pending) > 0
              h5.m-b-1.m-t-3(data-i18n="teacher.pending_credits")
              .row
                for prepaid in pending
                  .prepaid-card-container.col-sm-4.col-xs-6
                    +prepaidCard(prepaid, 'pending-prepaid-card')

            if _.size(empty) > 0
              h5.m-b-1(data-i18n="teacher.empty_credits")
              .row
                for prepaid in empty
                  .prepaid-card-container.col-sm-4.col-xs-6
                    +prepaidCard(prepaid, 'empty-prepaid-card')

          #actions-col.col-md-3
            +addCredits

        else
          // no prepaids
          .col-sm-6.col-sm-offset-3.col-lg-4.col-lg-offset-4
            +addCredits

mixin prepaidCard(prepaid, className)
  .prepaid-card.bg-navy.text-center.p-a-2(class=className)
    h1.m-t-2.m-b-0= prepaid.openSpots()
    if prepaid.get('type') === 'starter_license'
      div(data-i18n="teacher.starter_licenses")
    else
      div(data-i18n="teacher.licenses_remaining")
    div.m-t-1
      i.small-details
        if prepaid.usedSpots() === 1
          = translate('teacher.one_license_used')
        else
          = translate('teacher.num_licenses_used', {numLicensesUsed: prepaid.usedSpots()})
    hr
    i.small-details
      .pull-left(data-i18n="teacher.start_date")
      .pull-right= moment(prepaid.get('startDate')).utc().format('l')
      .clearfix

      .pull-left(data-i18n="teacher.end_date")
      .pull-right= moment(prepaid.get('endDate')).utc().format('l')
      .clearfix
  if prepaid.get('type') === 'course'
    .share-details.small-details.m-b-2
      if prepaid.get('creator') === me.id
        a.share-licenses-link(data-prepaid-id=prepaid.id)
          span(data-i18n="share_licenses.share_licenses")
      else if !prepaid.creator.loading
        span(data-i18n="share_licenses.shared_by")
        = " "
        a(href="mailto:" + prepaid.creator.get('email'))
          span= prepaid.creator.broadName()

mixin addCredits
  .text-center.m-b-3.m-t-3
    h5(data-i18n="courses.get_enrollments")
    if me.get('enrollmentRequestSent')
      #enrollment-request-sent-blurb.small
        p(data-i18n="teacher.enroll_request_sent_blurb1")
        p(data-i18n="teacher.enroll_request_sent_blurb2")
        p(data-i18n="[html]teacher.enroll_request_sent_blurb3")
      button#request-sent-btn.btn-lg.btn.btn-forest(disabled=true, data-i18n="teacher.request_sent")
    else
      p.m-y-2(data-i18n="teacher.get_enrollments_blurb")
      button#contact-us-btn.btn-lg.btn.btn-forest(data-i18n="contribute.contact_us_url")
